#![allow(dead_code)]

struct FnMutLrn {}

impl FnMutLrn {
    pub fn hello() {
        println!("FnMut learning!");
    }
}

#[cfg(test)]
mod tests {
    // use super::*;

    #[test]
    /// 可变借用
    /// FnMut 的实例可以重复调用，并且可以改变状态。
    fn test_fn_mut() {
        let mut x = 5;
        let mut inc = || x += 1;

        inc();
        assert_eq!(x, 6);
    }

    #[test]
    fn test_do_twice() {
        let mut x: usize = 2;
        let add_one = || x += 1;
        do_twice(add_one);
        assert_eq!(x, 4);
        fn do_twice<F>(mut func: F)
        where
            F: FnMut(),
        {
            func();
            func();
        }
    }
}
